//
//  QADetailListCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/11.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "QADetailListCell.h"

@implementation QADetailListCell

+ (CGFloat)calculateHeightWithModel:(CommonAnswerModel *)model {
    
    return 60 +  [Utilities getStringHeightWithText:model.answerContent font:[UIFont systemFontOfSize:15] viewWidth:(TTScreenWidth - 28)] + 15;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.userIcon pp_clipCorners:UIRectCornerAllCorners radius:self.userIcon.frame.size.height/2];
    });
}

- (void)fillWithModel:(CommonAnswerModel *)model Type:(QADetailSectionType)type {
    
    [self.userIcon sd_setImageWithURL:[NSURL URLWithString:model.imgUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.userName.text = model.nickname;
    self.QATimeLab.text = model.createTime;
    self.QAContentLab.text = model.answerContent;
    
    if ([model.source isEqualToString:@"3"]) {
        self.storeIcon.hidden = NO;
    } else {
        self.storeIcon.hidden = YES;
    }
    
    if ([model.isOptimization isEqualToString:@"1"]) {
        [self.QATagIcon setImage:[UIImage imageNamed:@"youzhi_icon"]];
    }
    
    if ([model.isSelected isEqualToString:@"1"]) {
        [self.QATagIcon setImage:[UIImage imageNamed:@"jingxuan_icon"]];
    }
    
    [self.AQThumbBtn setTitle:[NSString stringWithFormat:@" 有用%ld",(long)model.laudNumber] forState:UIControlStateNormal];

    if (model.isZan.length > 0) {
        [self.AQThumbBtn setImage:[UIImage imageNamed:@"tanhun_zan_sel"] forState:UIControlStateNormal];
        [self.AQThumbBtn setTitleColor:UIColorHex(0xFF4242) forState:UIControlStateNormal];
    } else {
        [self.AQThumbBtn setImage:[UIImage imageNamed:@"tanhun_zan"] forState:UIControlStateNormal];
        [self.AQThumbBtn setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];
    }
        
    
    switch (type) {
        case QADetailSectionType_highQuality:{
            
            self.QATagIcon.hidden = NO;
            
        } break;
        case ServiceCatNaviType_marvellous:{
            
            self.QATagIcon.hidden = YES;

        } break;

        default:
            break;
    }
}


- (IBAction)thumbAction:(id)sender {
    if (self.QADetailListCellBlock) {
        self.QADetailListCellBlock();
    }
}


@end
